package com.gaowl.yygh.commom.exception;

import com.gaowl.yygh.commom.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/*
* 全局异常处理类
* */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)   // 标明哪些异常调用此方法
    @ResponseBody   // 结果以JSON形式输出
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(HospitalException.class)
    @ResponseBody
    public Result error(HospitalException e) {
        e.printStackTrace();
        return Result.fail();
    }
}
